import { AxiosRequestConfig } from 'axios'
import { fuel } from './AxiosManage'

async function fuelRequest(baseParam: {}, option?: {}): Promise<any> {


    //拼接请求参数
    let reqParam
    if (option) {
        reqParam = Object.assign(option, baseParam)
    } else {
        reqParam = baseParam
    }

    try {
        const rst = await fuel.request(reqParam)
        console.log('rst :>> ', rst);

        return Promise.resolve(rst)
    } catch (err) {
        Promise.reject(err)
    }

}

async function fuelGet(url: string, params?: any, option?: {}) {

    const baseParam = {
        url: url,
        method: "GET",
        params: params,
    }

    return fuelRequest(baseParam, option)
}



async function fuelPost(url: string, params?: any, option?: {}) {

    const baseParam = {
        url: url,
        method: "POST",
        data: params
    }

    return fuelRequest(baseParam, option)
}

export {
    fuelGet, fuelPost, fuelRequest
}

